public class ChatAdapter extends ArrayAdapter<Message> {

    private int id;
    private View view;
    private ViewHolder viewHolder;

    public ChatAdapter(Context context, int id, List<Message> objects) {
        super(context, resource, objects);
        this.id = id;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView != null){
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }else{
            view = LayoutInflater.from(getContext()).inflate(resourceId, null);
            viewHolder = new ViewHolder();
            viewHolder.leftMessage = (RelativeLayout) view.findViewById(R.id.leftMessage);
            viewHolder.rightMessage = (RelativeLayout) view.findViewById(R.id.rightMessage);
            viewHolder.leftPanel = (RelativeLayout) view.findViewById(R.id.leftPanel);
            viewHolder.rightPanel = (RelativeLayout) view.findViewById(R.id.rightPanel);
            viewHolder.sending = (ProgressBar) view.findViewById(R.id.sending);
            viewHolder.error = (ImageView) view.findViewById(R.id.sendError);
            viewHolder.sender = (TextView) view.findViewById(R.id.sender);
            viewHolder.rightDesc = (TextView) view.findViewById(R.id.rightDesc);
            viewHolder.leftpic=(ImageView)view.findViewById(R.id.leftAvatar001);
            viewHolder.rightpic=(ImageView)view.findViewById(R.id.rightAvatar001) ;
            viewHolder.rightzz=(LinearLayout)view.findViewById(R.id.wx_show_zz_me);
            viewHolder.hb=(RelativeLayout) view.findViewById(R.id.message_hb);
            viewHolder.hb_name=(TextView)view.findViewById(R.id.messsage_hb_name);
            viewHolder.systemMessage = (TextView) view.findViewById(R.id.systemMessage);
            viewHolder.lv=(TextView)view.findViewById(R.id.left_voice);
            viewHolder.rv=(TextView)view.findViewById(R.id.right_voice);
            view.setTag(viewHolder);
        }
        if (position < getCount()){
            final Message data = getItem(position);
            data.showMessage(viewHolder, getContext());
        }
        return view;
    }
    public class ViewHolder{
        public RelativeLayout leftMessage;
        public RelativeLayout rightMessage;
        public RelativeLayout leftPanel;
        public RelativeLayout rightPanel;
        public ProgressBar sending;
        public ImageView error;
        public TextView sender;
        public TextView systemMessage;
        public TextView rightDesc,hb_name;
        public ImageView rightpic,leftpic;
        public LinearLayout rightzz;
        public RelativeLayout hb;
        public TextView lv,rv;
    }
}
